<?php

namespace App\Models\Music;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Model;

/**
 * 用户模型层
 *
 * Class Role
 * @package App\Models\Adv
 */
class Music extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    public $table = 'music';
    public $type_status = [0 =>'常规发布', 1 =>'独家首发',2 =>'独家',3 =>'特殊授权'];
    public $dates = [];
    public $appends = ['type_status_text'];
    /**
     * Indicates if the model should be timestamped.
     * @var bool
     */
    public $timestamps = false;

    public function music_file(){
        return $this->hasOne('App\Models\Files\Files','uuid','music_file_uuid');
    }

    public function accompaniment_file(){
        return $this->hasOne('App\Models\Files\Files','uuid','accompaniment_file_uuid');
    }

    public function mv_file(){
        return $this->hasOne('App\Models\Files\Files','uuid','mv_file_uuid');
    }

    public function video_file(){
        return $this->hasOne('App\Models\Files\Files','uuid','video_file_uuid');
    }

    public function karaoke_file(){
        return $this->hasOne('App\Models\Files\Files','uuid','karaoke_file_uuid');
    }

    public function music_check(){
        return $this->hasOne('App\Models\Music\MusicCheck','music_id','id');
    }

    public function music_sp(){
        return $this->hasMany('App\Models\Music\MusicSp','library_id','library_id');
    }

    public function albums(){
        return $this->belongsTo('App\Models\Music\Albums','album_id','id')->select('id','name');
    }

    public function user(){
        return $this->hasManyThrough('App\Models\Agent\Agent','App\Models\User\UsersInfo','id','software_id','user_id','software_id');
    }

    public function users_info(){
        return $this->belongsTo('App\Models\User\UsersInfo','user_id','id');
    }

    public function company(){
        return $this->belongsTo('App\Models\Company\Company', 'company_id','id')->select('id','company_name','company_image');
    }

    public function special(){
        return $this->belongsTo('App\Models\Music\Special','special_id','id');
    }


    public function getTypeStatusTextAttribute()
    {
        if($this['type_status']) {
            return $this->type_status[$this['type_status']];
        }else{
            return $this->type_status[0];
        }
    }

}
